package com.akk.module.admin.service;

import com.akk.module.admin.entity.Admin;
import com.akk.module.admin.entity.AdminExample;
import com.akk.module.admin.mapper.AdminMapper;
import com.akk.module.admin.mapper.dao.AdminDao;
import com.akk.module.admin.model.response.AdminRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AdminService {
    @Autowired
    AdminMapper adminMapper;
    @Autowired
    AdminExample adminExample;
    @Autowired
    AdminDao adminDao;
    public List<Admin> findByPhone(String phone) {
        adminExample.clear();
        adminExample.createCriteria().andPhoneEqualTo(phone);
        return adminMapper.selectByExample(adminExample);
    }

    public List<Admin> findByAccount(String account) {
        adminExample.clear();
        adminExample.createCriteria().andAccountEqualTo(account);
        return adminMapper.selectByExample(adminExample);
    }

    public List<Admin> findByAccountAndAppId(String account, String appId) {
        adminExample.clear();
        adminExample.createCriteria().andAccountEqualTo(account).andAppIdEqualTo(appId);
        return adminMapper.selectByExample(adminExample);
    }

    public void save(Admin admin) {
        adminMapper.insert(admin);
    }

    public List<AdminRes> findByParam(String adminId) {
        return adminDao.selectAdminListByFromAdminId(adminId);
    }

    public Admin findByAdminId(String adminId) {
        return adminMapper.selectByPrimaryKey(adminId);
    }

    public void update(Admin admin) {
        adminMapper.updateByPrimaryKey(admin);
    }

    public void deleteByAdminId(String adminId) {
        adminMapper.deleteByPrimaryKey(adminId);
    }

    public List<Admin> findByRoleId(String roleId) {
        adminExample.clear();
        adminExample.createCriteria().andRoleIdEqualTo(roleId);
        return adminMapper.selectByExample(adminExample);
    }
}
